﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerCtrScript : MonoBehaviour {


    [SerializeField]
    private float speed = 10f;
    private bool jump;
    [SerializeField]
    private float jumpSpeed = 400f;

    private Rigidbody2D rigidbody2d;

    private void Awake() {

        rigidbody2d = GetComponent<Rigidbody2D>();

    }

    // Update is called once per frame
    void Update () {
		
	}

    private void FixedUpdate() {

        float h = Input.GetAxis("Horizontal");

        //Debug.Log("h = " + transform.position.x + h * speed * Time.deltaTime);

        if (h < 0) {

            //rigidbody2d.AddForce(Vector2.left * Mathf.Abs(h) * speed);
            //rigidbody2d.velocity = Vector2.right * h * speed;
            transform.position = new Vector3(transform.position.x + h * speed * Time.deltaTime
           ,transform.position.y);

            transform.localScale = new Vector3(-1,1,1);


        }

        if (h > 0) {
            //rigidbody2d.AddForce(Vector2.right * h * speed);
            //rigidbody2d.velocity = Vector2.right * h * speed;
            transform.position = new Vector3(transform.position.x + h * speed * Time.deltaTime
           ,transform.position.y);

            transform.localScale = new Vector3(1,1,1);
        }

        if (Input.GetButtonDown("Jump")) {
            Debug.Log("Jump");
            rigidbody2d.AddForce(Vector2.up * jumpSpeed);
        }

    }
}
